from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
# 基类
class Base():
    def __init__(self,driver):
        self.driver=driver
    # 打开网址
    def open_url(self,url):
        self.driver.get(url)
    def find_element(self,loc):
        try:
            WebDriverWait(self.driver,20,0.5).until(lambda driver: driver.find_element(*loc).is_displayed())
            return self.driver.find_element(*loc)
        except Exception as e:
            print(e)
    # 点击
    def click(self,loc):
        self.find_element(loc).click()
    # 输入
    def send_keys(self,loc,info):
        self.find_element(loc).send_keys(info)
    # 文本
    def text(self,loc):
        return self.find_element(loc).text
    # 清空
    def clear(self,loc):
        self.find_element(loc).clear()
    # 键盘回车
    def Enter(self,loc):
        self.find_element(loc).send_keys(Keys.ENTER)
    # iframe
    def iframe(self,loc):
        self.driver.switch_to.frame(self.find_element(loc))
    # 退出iframe
    def iframe_un(self):
        self.driver.switch_to.default_content()
    # 切换窗口
    def handles(self):
        self.driver.switch_to.window(self.driver.window_handles[-1])
    # 滚动
    def scroolTo(self):
        self.driver.execute_script('window.scrollTo(0,500)')
    # 弹窗
    def alert(self):
        alert = self.driver.switch_to.alert
        alert.accept()
    # 鼠标
    def action(self,loc):
        ActionChains.double_click(self.find_element(loc)).perform()